package com.lovo.shirodemo.controller;

import com.lovo.shirodemo.model.dto.UserInfoDTO;
import com.lovo.shirodemo.result.GlobalHandleException;
import com.lovo.shirodemo.result.ResponseResult;
import com.lovo.shirodemo.result.ResultCode;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexController {
    @RequestMapping("/login")
    @ResponseResult
    public Object toLogin() throws GlobalHandleException {
        throw new GlobalHandleException(ResultCode.USER_AUTHENTICATION_ERROR);
    }
    @RequestMapping("/403")
    @ResponseResult
    public Object to403() throws GlobalHandleException {
        throw new GlobalHandleException(ResultCode.USER_AUTHORIZATION_ERROR);
    }

    @GetMapping("/getUser")
    @ResponseResult
    public Object getUser() throws GlobalHandleException {
        return SecurityUtils.getSubject().getPrincipal();
    }
    @GetMapping("/logout")
    @ResponseResult
    public Object logout() throws GlobalHandleException {
        SecurityUtils.getSubject().logout();
        return null;
    }
}
